package cn.emailChat.ai.repo;

import cn.emailChat.ai.domain.Email;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

/**
 * @Description Email表的持久化、查询和更新
 * @Author susu
 * @Date 2025/8/18
 */
public interface EmailRepo extends JpaRepository<Email, Long> {

    Optional<Email> findByMessageId(String messageId);

    // 近 N 封（同一个联系人）
    List<Email> findByFromEmailOrderBySendTimeDesc(String fromEmail, Pageable pageable);

    // 时间窗内（同一个联系人）
    List<Email> findByFromEmailAndSendTimeAfterOrderBySendTimeDesc(String fromEmail, LocalDateTime after);
}